<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>

</head>
<body>
    <div id="app">
        <p>{{gender}}</p>
        <p>{{genderDes}}</p>
        <p>{{genderDesByMethods()}}</p>
    </div>    

    <script>
        var app = new Vue({
            el:"#app",
            data:{
              gender:0,
            },
            computed:{
                genderDes(){
                    if(this.gender==0){
                        return "女生";
                    }
                    if(this.gender==1){
                        return "男生";
                    }
                    if(this.gender==2){
                        return "中性";
                    }
                    if(this.gender==3){
                        return "未知";
                    }
                }
            },
            // 通过方法的调用 也可以实现计算属性的效果
            methods:{
                genderDesByMethods(){
                    if(this.gender==0){
                        return "女生";
                    };
                    if(this.gender==1){
                        return "男生";
                    };
                    if(this.gender==2){
                        return "中性";
                    };
                    if(this.gender==3){
                        return "未知";
                    };
                }
            },
        });
    </script>
</body>
</html>